home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / scale3d.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  66 lines

  1. ; $Id: scale3d.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. pro scale3d        ;Scale !p.t to bring unit cube into viewing area
  7. ;+
  8. ; NAME:
  9. ;    SCALE3D
  10. ;
  11. ; PURPOSE:
  12. ;    Scale the 3D unit cube (a cube with the length of each side equal
  13. ;    to 1) into the viewing area.
  14. ;
  15. ; CATEGORY:
  16. ;    Graphics, 3D.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    SCALE3D
  20. ;
  21. ; INPUTS:
  22. ;    No explicit inputs.  !P.T is an implicit input.
  23. ;
  24. ; KEYWORD PARAMETERS:
  25. ;    None.
  26. ;
  27. ; OUTPUTS:
  28. ;    No explicit outputs.  !P.T is an implicit output.
  29. ;
  30. ; COMMON BLOCKS:
  31. ;    None.
  32. ;
  33. ; SIDE EFFECTS:
  34. ;    !P.T is modified.
  35. ;
  36. ; RESTRICTIONS:
  37. ;    Doesn't work for all forms of perspective transformations.
  38. ;
  39. ; PROCEDURE:
  40. ;    Eight, 3D data points are created at the vertices of the 3D
  41. ;    unit cube.  They are transformed by !P.T.  The system
  42. ;    is translated to bring the minimum (x,y,z) point to the origin, 
  43. ;    and then scaled to make each coordinates maximum value equal to 1.
  44. ;
  45. ; MODIFICATION HISTORY:
  46. ;    DMS, May, 1988.
  47. ;-
  48.  
  49. on_error,2              ;Return to caller if an error occurs
  50. for i = 0,7 do begin    ;Find 8 corners
  51.     p = [ i and 1, (i/2) and 1, ((i/4) and 1),1] # !p.t
  52.     p = p / p[3]    ;normalize homogenous coords
  53.     if i eq 0 then begin
  54.         pmin = p & pmax = p
  55.       endif else begin
  56.         pmin = pmin < p & pmax = pmax > p
  57.       endelse
  58.     endfor
  59. ;
  60. ;print,'PMAX: ',transpose(pmax)
  61. ;print,'PMIN: ',transpose(pmin)
  62. ;    avoid dividing by 0 if there is no Z transformation.
  63. if pmax[2] eq pmin[2] then pmax[2] = pmin[2]+1
  64. t3d,tr = [ -pmin[0], -pmin[1], -pmin[2]], sc=1./(pmax[0:2]-pmin[0:2])
  65. end
  66.